//
//  CCViewController.m
//  test02
//
//  Created by lzh on 2020/11/23.
//  Copyright © 2020 NO. All rights reserved.
//

#import "CCViewController.h"
#import "JYNode.h"
#import "ArtBannerList.h"
#import "CCTableViewCell.h"
#import "CCViewModel.h"
@interface CCViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)CCViewModel * cc_viewModel;
@end

@implementation CCViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.cc_viewModel = [[CCViewModel alloc]init];
    self.view.backgroundColor = [UIColor whiteColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    [self registerCells];
    
    [self.cc_viewModel addData];
    [self.tableView reloadData];
    [self doRequestRefresh:YES];
}

- (void)doRequestRefresh:(BOOL)aRefresh{
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self sendNext:nil refresh:aRefresh];
    });
    
}

- (UITableViewStyle)tableViewStyle{
    return UITableViewStylePlain;
}

-(void)registerCells{
    
    JYNode * node1 = [JYNode nodeContentClass:[ArtBannerList class] config:^(__kindof JYNode *node) {
        
        [node addCellNode:[JYCellNode cellClass:[CCTableViewCell class] config:^(JYCellNode *cellNode) {
            
        }]];
    }];
    
    [self.cc_viewModel registCellNodes:@[node1] byTableView:self.tableView cellDelegate:self];
}

#pragma mark - UITableViewDataSource, UITableViewDelegate


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [self.cc_viewModel numberOfSections];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.cc_viewModel numberOfRowsInSection:section];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [self.cc_viewModel heightForRowAtIndexPath:indexPath config:^(UITableViewCell *aCell, __kindof JYBaseNode *aNode) {
        
    }];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [self.cc_viewModel cellForRowAtIndexPath:indexPath config:^(UITableViewCell *aCell, __kindof JYBaseNode *aNode) {
         
    }];
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 0.0001;
    }
    
    return 0.0001;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
//    if (self.cc_viewModel.banners.count && section == 0) {
//        return 0.0001;
//    }
    return 0.0001;
}

@end
